<?php
class BaseTable{
	const SORT_MEMBER = 'sortmember';
	public $cols = array();
	public $class = 'table';
	public $hasOrdinal;
	public $hasCheckbox;
	public $data;
	public function __construct($data){
		$this->hasOrdinal = true;
		$this->hasCheckbox = false;
		$this->data = $data;
	}
	public function render(){
		echo '<table class="'.$this->class.'">';
		echo '<thead><tr>';
		if($this->hasCheckbox){
			echo '<th><input type="checkbox" name="checkall"></td>';
		}
		if($this->hasOrdinal){
			echo '<th>#</td>';
		}
		foreach ($this->cols as $key=>$value) {
			echo '<th '.BaseTable::SORT_MEMBER.'="'.$key.'">'.$value.'</th>';
		}
		echo '<tr><thead>';
		echo '<tbody>';
		$i = 1;
		foreach ($this->data as $key=>$value) {
			$focus = '';if($i%2 == 0)$focus = 'class="focus"';
			echo '<tr '.$focus.'>';
			if($this->hasCheckbox){
				echo '<td><input type="checkbox" name="'.$this->getClass().$i.'"></td>';
			}
			if($this->hasOrdinal){
				echo '<td>'.$i.'</td>';
			}
			foreach ($this->cols as $skey=>$svalue) {
				echo '<td>'.$value[$skey].'</td>';
			}
			echo '</tr>';
			$i++;
		}
		echo '</tbody>';
		echo '</table>';		
	}
	public function getClass(){
		return get_class($this);
	}
}